﻿#include "myrowdelegate.h"

MyRowDelegate::MyRowDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
// 获取已打印的
QSet<int> &MyRowDelegate::getGreenRows() {
    return greenRows;
}

// 批量添加多行，使其字体颜色变为绿色
void MyRowDelegate::addGreenRows(const QSet<int> &rows) {
    greenRows.unite(rows);
}

// 设置需要高亮的行号集合
void MyRowDelegate::setGreenRows(const QSet<int> &rows) {
    greenRows = rows;
}

// 添加需要高亮的行号
void MyRowDelegate::addGreenRow(int row) {
    greenRows.insert(row);
}

// 删除不需要高亮的行号
void MyRowDelegate::removeGreenRow(int row) {
    greenRows.remove(row);
}

// 清除所有高亮的行号
void MyRowDelegate::clearGreenRows() {
    greenRows.clear();
}

// 判断行是否高亮
bool MyRowDelegate::isRowGreen(int row) {
    return greenRows.contains(row);
}

// 绘制绿色背景
void MyRowDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index)const{
    if (greenRows.contains(index.row())) {
        QColor lightGreen(Qt::green);
        lightGreen.setAlpha(150);
        painter->fillRect(option.rect, lightGreen);
    }
    QStyledItemDelegate::paint(painter, option, index);
}
